
GrowlNotification = Class.create();
GrowlNotification.prototype = Object.extend(new BuildObserver(), {
  
  SUCCEEDED_IMG: 'images/icon-spinner.gif',
  FAILED_IMG: 'images/orange-spinner.gif',
  ERROR_IMG: 'images/white-spinner.gif',
  
  initialize: function() {
    this.register();
    if(window.widget) {
      this.basePath = window.widget.system('/bin/pwd', null).outputString.gsub(/\n/, '');
    }else {
      this.basePath = ''
    }
  },
  
  onSuccess: function(build) {
    this.notifyGrowl(build.message(), build.committers(), this.SUCCEEDED_IMG);
  },

  onFailure: function(build) {
    this.notifyGrowl(build.message(), build.committers(), this.FAILED_IMG);
  },
  
  onError: function(build) {
    this.notifyGrowl(build.message(), build.link(), this.ERROR_IMG)
  },

  notifyGrowl: function(title, description, img) {
    img = this.basePath + '/' + img
    if(window.widget) {
      command = "/usr/bin/osascript ./growl/notify.scpt '" + title + "' '" + description + "' '" + img + "'";
      window.widget.system(command, null);
    }else {
      alert(title + "\n" + description + "\n" + img);
    }
  },
  
  register: function() {
    if(window.widget) {
      window.widget.system("/usr/bin/osascript ./growl/register.scpt", null);
    }else {
      alert('register');
    }
  }
});
